#include "dialog.h"
#include "QPainter"
#include "QTime"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{
    int i;
    for(i=0;i<11;i++)
    {
        z[i]=qrand()%300;
    }

    this->startTimer(250);
}

Dialog::~Dialog()
{

}
void Dialog::paintEvent(QPaintEvent *)
{
    int c;
    QPainter painter(this);
    QPen pen(Qt::SolidLine);
    painter.setPen(pen);
    painter.drawLine(0,300,300,300);
    painter.drawLine(300,0,300,300);
    painter.drawLine(0,0,0,300);
    painter.drawLine(0,0,300,0);
    pen.setStyle(Qt::DotLine);//shi xiang
    pen.setColor(QColor(253,123,34));
    painter.setPen(pen);
    int a;
    for(a=0;a<300;a+=30)
    {
        painter.drawLine(0,a,300,a);
    }
        int b;
    for(b=0;b<300;b+=30)
        {
            painter.drawLine(b,0,b,300);
        }

    pen.setStyle(Qt::SolidLine);//xuxian
        pen.setColor(QColor(0,0,255));
        painter.setPen(pen);
        for(c=0;c<10;c++)
        {
            painter.drawLine(30*c,z[c],30*c+30,z[c+1]);

        }

}
void Dialog::timerEvent(QTimerEvent *)
{
    int c;
    for(c=0;c<10;c++)
    {
        z[c]=z[c+1];
    }
        z[10]=rand()%300;
    this->repaint();
}
